<template>
  <a-modal
    :width="1200"
    :visible="visible"
    :confirmLoading="confirmLoading"
    @ok="handleSubmit"
    @cancel="handleCancel"
    cancelText="关闭"
  >
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="12">
          <a-col :md="6" :sm="8">
            <a-form-item
                    label="标题"
                    :maxLength="50">
              <a-input placeholder="请输入标题" v-model="queryParam.itemName"></a-input>
            </a-form-item>
          </a-col>
          <a-col :md="6" :sm="8">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="refreshs" icon="search">查询</a-button>
            </span>
          </a-col>
        </a-row>
      </a-form>
      <div class="table-operator">
        <a-button @click="modalEditadd" type="primary" icon="plus">添加</a-button>
      </div>
    <a-table
            row-key="index"
            size="middle"
            :columns="columns"
            :dataSource="dataSource"
            :pagination="{ pageSize: 10 }"
    >
                <span slot="action" slot-scope="text, record">
                   <a @click="handleEdit(record)" >
            <a-icon type="edit"/>编辑</a>
                </span>
    </a-table>
      <eva-question-edit ref="modalEdit" @ok="refreshs"></eva-question-edit>
    </div>
  </a-modal>
</template>

<script>
  import pick from 'lodash.pick'
  import { getAction,postAction } from '@/api/manage'
  import EvaQuestionEdit from '../evaQuestion/EvaQuestionEdit'

  export default {
    name: 'EvaInfoPeizhi',
    components: { EvaQuestionEdit },
    data () {
      return {
        visible: false,
        confirmLoading: false,
          queryParam: {
              itemName: ''
          },
        formInfo: {},
          columns: [
              {
                  title: '顺序',
                  align: 'center',
                  dataIndex: 'itemNum'
              },
              {
                  title: '内容',
                  align: 'center',
                  dataIndex: 'itemName'
              },
              {
                  title: '试题类型',
                  dataIndex: 'selectType',
                  align: 'center',
                  customRender: (text) => this.$sysDictFilter(text, 'select_type')
              },
              {
                  title: '是否必选',
                  dataIndex: 'isMust',
                  align: 'center',
                  customRender: (text) => this.$sysDictFilter(text, 'whetherFlag')
              },
              {
                  title: '操作',
                  dataIndex: 'action',
                  align: 'center',
                  fixed: 'right',
                  scopedSlots: { customRender: 'action' }
              }
          ],
          dataSource:[],
        url: {
          saveInfo: '/system/evaInfo/save',
          getInfo: '/system/evaInfo/info',
            list: '/system/evaQuestion/list',
            delete: '/system/evaQuestion/delete'
        }
      }
    },
    created () {
    },
    methods: {
      show (record) {
        this.formInfo = Object.assign({}, record)
        if (this.formInfo.id) {
            console.log(this.formInfo)
            postAction(this.url.list, {pageNo:1, 'infoid': record.id }).then(res => {

                this.dataSource = res.result.data.records
          })
        }
        this.visible = true
      },
        refreshs(){
          const  parameter = {pageNo:1, 'infoid': this.formInfo.id };
            postAction(this.url.list, Object.assign(parameter, this.queryParam)).then(res => {
                console.log(res)
                this.dataSource = res.result.data.records
            })
        },
        modalEditadd() {
            this.$refs.modalEdit.edits(this.formInfo.id)// 确定
        },
        handleEdit(record){
            this.$refs.modalEdit.edit(record);
        },
      handleSubmit () {
        this.visible = false
      },
      // 关闭
      handleCancel () {
        this.close()
      },
      close () {
        this.visible = false
      }
    }
  }
</script>
